package com.wn55.hrms.util;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

public class SimpleRedisPoolUtil {
    private static volatile SimpleRedisPoolUtil instance ;

    private SimpleRedisPoolUtil(){}

    public static SimpleRedisPoolUtil getInstance(){
        if (instance == null){
            synchronized (SimpleRedisPoolUtil.class){
                if (instance == null){
                    instance = new SimpleRedisPoolUtil();
                }
            }
        }

        return instance ;
    }

    //测试简单的连接池
    public void testSimplePool(){
        JedisPoolConfig config = new JedisPoolConfig();
        //设置连接池属性
        config.setMaxTotal(20);
        config.setMaxIdle(10);
        config.setMinIdle(2);

        JedisPool pool = new JedisPool(config,"127.0.0.1",6379);

        Jedis jedis = pool.getResource();
        //操作 redis 数据库

        //不是销毁  还回到 连接池
        jedis.close();
    }

}
